home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / comm / net / spakparnet_0_5.lha / han / thing / act_open.c < prev    next >
C/C++ Source or Header  |  1992-11-09  |  5KB  |  168 lines

  1. /********************************************************************
  2.  ** NETWORK FILESYSTEM - DOS HANDLER
  3.  **
  4.  ** (c) Spak, Darrell Tam, c9107253@ee.newcastle.edu.au (1994)
  5.  ** phone (Australia) 049-829-710
  6.  **                   +49-829-710
  7.  ** (c) SST 1994
  8.  **
  9.  ** OPEN (ACTION_FINDINPUT | ACTION_FINDOUTPUT | ACTION_UPDATE)
  10.  **
  11.  ** Actions are sent to the network device
  12.  **
  13.  ** NOW supports shells on CON: type devices, 
  14.  ** passes on the first "Open", consequent ones are simply ignored
  15.  ** and returned with the same fh_Arg1. See interactive.s
  16.  **
  17.  ** TABS to 4
  18.  ********************************************************************/
  19.  
  20. #include "/snd/everything.h"
  21. #include "deadheads.h"
  22. #include "root_protos.h"
  23. #include "globs_protos.h"
  24. #include "xtra_protos.h"
  25. #include "interactive_protos.h"
  26.  
  27. #define OPEN_PKTMSG_SIZE sizeof(struct OpenPktMsg)
  28.  
  29. /** this is just a variation of the "doofus" format */
  30. struct OpenPktMsg {
  31.     struct    DoofusPktMsg    dpm;
  32.  
  33.     struct    NFSOpenFile            openreq;    /* request structure */
  34.     struct    NFSOpenFileReturn    openret;    /* return structure */
  35.     struct    FileArg1            *fa1;
  36. };
  37.  
  38.  
  39. /********************************************************************/
  40. static long handle_openfile_net(struct OpenPktMsg *opm)
  41. /********************************************************************/
  42. {
  43. struct DosPacket *dosmsg = opm->dpm.dp_original;
  44. struct FileHandle *fh = BTOC(dosmsg->dp_Arg1);
  45. struct FileArg1    *fa1 = opm->fa1;
  46.  
  47. { unsigned char tt[100]; spf(tt, 100, "open: res1=%ld, res2=%ld",
  48.         opm->openret.remote_res1, opm->openret.remote_res2); MyPrint(win1, tt); }
  49.  
  50.     dosmsg->dp_Res2 = opm->openret.remote_res2;
  51.     if(opm->dpm.net.pm.smsg.result == PAR_OK &&
  52.         (dosmsg->dp_Res1 = opm->openret.remote_res1) ) {
  53.  
  54.         fa1->remote.remote_ifh    = opm->openret.remote_ifh;
  55.         fa1->remote.majic         = opm->openret.remote_majic;
  56.  
  57.     /** IS THE FILE INTERACTIVE?? IF SO, GIVE IT ANOTHER PORT */
  58.         if(*(long *)&fh->fh_Port = opm->openret.remote_ifh_Port) {
  59.         struct InterPort *imp;
  60.             if(imp = AllocRemember(&fa1->mem,
  61.                         INTER_MSGPORT_SIZE, MEMF_PUBLIC | MEMF_CLEAR)) {
  62.                 imp->i.is_Code             = handle_interactive_stuff;
  63.                 imp->i.is_Data             = imp;
  64.                 imp->mp.mp_Node.ln_Type    = NT_MSGPORT;
  65.                 imp->mp.mp_Flags        = PA_SOFTINT;
  66.                 imp->mp.mp_SigTask        = (struct Task *)&imp->i;
  67.                 NewList(&imp->mp.mp_MsgList);
  68.                 imp->fa1 = fa1;
  69.                 imp->pass = localrepport;
  70.                 imp->opencount = 1;
  71.                 dosmsg->dp_Port = imp;            /* new port for every interactive */
  72.             }
  73.         }
  74.         fh->fh_Type = dosmsg->dp_Port;            /* already contains "OurPort" */
  75.         fh->fh_Arg1 = (long)fa1;
  76.     }
  77.  
  78. /** ERROR ??? */
  79.     else {
  80.         REMOVE_FROM_LIST(fa1, first_fa1);        /* no longer open */
  81.         FreeMem(fa1, FA1_SIZE);                    /* gone */
  82.         dosmsg->dp_Res1 = 0;
  83.         if(opm->dpm.net.pm.smsg.result != PAR_OK) dosmsg->dp_Res2 = ERROR_NO_DISK;
  84.     }
  85.     return(AR_FLAG_RETURNDOSMSG | AR_FLAG_FREEDOOF);
  86. }
  87.  
  88.  
  89.  
  90. /********************************************************************/
  91. long action_openfile(struct DosPacket *dosmsg,
  92.                             struct MsgPort *dm_retport)
  93. /********************************************************************/
  94. {
  95. unsigned char *fname = BTOC(dosmsg->dp_Arg3);    /* note, BCPL style string */
  96. short    server;
  97.  
  98. { unsigned char tt[60]; spf(tt,60,"fh=%lx, lock=%lx, task=%lx",
  99.         dosmsg->dp_Arg1, dosmsg->dp_Arg2, dosmsg->dp_Port->mp_SigTask);
  100.         MyPrint(win1, tt); }
  101.  
  102. /** IF THERE IS A LOCK */
  103.     if(dosmsg->dp_Arg2) {
  104.         dosmsg->dp_Res1 = 0; dosmsg->dp_Res2 = ERROR_OBJECT_NOT_FOUND;
  105.         return(AR_FLAG_RETURNDOSMSG);
  106.     }
  107.     else if(fname[0] == 1 && fname[1] == '*') {
  108.         dosmsg->dp_Res1 = 0; dosmsg->dp_Res2 = ERROR_OBJECT_NOT_FOUND;
  109.         return(AR_FLAG_RETURNDOSMSG);
  110.     }
  111.  
  112. /** CHECK OUT THE FILE NAME */
  113.     MyPrintBCPL(win1,dosmsg->dp_Arg3);
  114.  
  115.     server = fname[6]-'0';
  116.     if(fname[5] == ',' && server >=0 && server<=9 &&
  117.                                 fname[0] > 7 && netservport[server]) {
  118.     struct OpenPktMsg    *opm;
  119.     struct FileArg1        *fa1;
  120.     unsigned char        *send_name;
  121.     short    send_name_len = fname[0] - 7+2;
  122.  
  123.         if(!(fa1 = AllocMem(FA1_SIZE, MEMF_PUBLIC)) ||
  124.            !(opm = AllocMem(OPEN_PKTMSG_SIZE + send_name_len, MEMF_PUBLIC)) ) {
  125.             FreeMem(fa1, FA1_SIZE);
  126.             dosmsg->dp_Res1 = 0; dosmsg->dp_Res2 = ERROR_NO_FREE_STORE;
  127.             return(AR_FLAG_RETURNDOSMSG);
  128.         }
  129.  
  130.         opm->fa1 = fa1;
  131.  
  132.         send_name        = (unsigned char *)&opm[1];
  133.         send_name[0]    = fname[0] - 7;
  134.         spf(&send_name[1], send_name_len-1, &fname[8]);
  135.  
  136.         opm->openreq.request     = REQUEST_OPENFILE;
  137.         opm->openreq.action     = dosmsg->dp_Type;
  138.         opm->openreq.internallock = NULL;                /* for the moment */
  139.  
  140.         ADD_HEAD(fa1, first_fa1);                        /* add into the list */
  141.         fa1->Type        = LK_REMOTE;
  142.         fa1->fh         = BTOC(dosmsg->dp_Arg1);        /* (don't really use it tho) */
  143.         fa1->parent_lock = BTOC(dosmsg->dp_Arg2);        /* lock we're from */
  144.         fa1->mem        = NULL;
  145.  
  146.         INIT_DOOFPKTMSG(&opm->dpm,
  147.                     handle_openfile_net,
  148.                     netrepport,
  149.                     fa1->fsys = netservport[server],
  150.                     dosmsg,
  151.                     dm_retport,
  152.                     OPEN_PKTMSG_SIZE+send_name_len,
  153.                     fa1->remote.machine = fname[7],
  154.                     fa1->remote.service = SERV_FILE,
  155.                     &opm->openreq, sizeof(struct NFSOpenFile),    /* request */
  156.                     send_name, send_name_len,                    /* send-body */
  157.                     NULL, 0,                                    /* result-body */
  158.                     &opm->openret, sizeof(struct NFSOpenFileReturn));
  159.                                                                 /* return codes */
  160.     { unsigned char tt[100]; spf(tt, 100, "port=%lx", opm->dpm.net.server); MyPrint(win1, tt); }
  161.  
  162.         PutMsg(opm->dpm.net.server, opm);
  163.         return(0);
  164.     }
  165.     dosmsg->dp_Res1 = 0; dosmsg->dp_Res2 = ERROR_OBJECT_NOT_FOUND;
  166.     return(AR_FLAG_RETURNDOSMSG);
  167. }
  168.